package top.zhimingw.tankgame4;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @Author:zhimingw
 * @Version 1.0
 */
public class ZhimingwTankGame04 extends JFrame {

    //定义一个MyPanel
    MyPanel mp = null;
    public static void main(String[] args) {
        ZhimingwTankGame04 zhimingwTankGame01 = new ZhimingwTankGame04();

    }

    public ZhimingwTankGame04(){
        System.out.println("请输入选择1：新游戏 2：继续上局");
        Scanner sc = new Scanner(System.in);
        String key = sc.next();
        mp = new MyPanel(key);
        //将mp放入Thread
        Thread thread = new Thread(mp);
        thread.start();
        this.add(mp);
        this.add(mp);
        this.setSize(1300,950);
        this.addKeyListener(mp);//监听键盘事件
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //关闭窗口监听
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }

}
